package Database;

import Entity.Role;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author CONG
 */
public class RoleDB {
    private ConnectDB conn;

    public RoleDB() {
        conn=new ConnectDB();
    }
    public ArrayList<Role> getRolesList(){
        ArrayList<Role> listRole=new ArrayList<Role>();
        try {
            CallableStatement cstmt=conn.connect().prepareCall("{call getRolesList}");
            ResultSet rs=cstmt.executeQuery();
            while(rs.next()){
                int roleCode=rs.getInt("RoleCode");
                String name=rs.getString("Name");
                int loanTypeCode=rs.getInt("LoanTypeCode");
                Role r=new Role(roleCode, name, loanTypeCode);
                listRole.add(r);
            }
        } catch (Exception ex) {
            Logger.getLogger(RoleDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listRole;
    }
}
